/*
@header({
  searchable: 0,
  filterable: 1,
  quickSearch: 0,
  title: '央视频',
  lang: 'dr2'
})
*/

var rule = {
    title: '央视频',
    host: 'https://api.cntv.cn',
    homeUrl: '/lanmu/columnSearch?&fl=&fc=&cid=&p=1&n=500&serviceId=tvcctv&t=json',
    //lanmu/columnSearch?&fl=&fc=&cid=&p=1&n=20&serviceId=tvcctv&t=jsonp&cb=Callback
    url: '/list/getVideoAlbumList?fyfilter&area=&letter=&n=24&serviceId=tvcctv&t=json',

    searchUrl: '',
    searchable: 0,
    quickSearch: 0,
    class_name: '4K专区&电视剧&动画片&栏目大全&特别节目&纪录片',
    class_url: '4K专区&电视剧&动画片&栏目大全&特别节目&纪录片',
    filterable: 1,
    filter_url: 'channel={{fl.channel}}&sc={{fl.sc}}&bigday={{fl.bigday}}&year={{fl.year}}',
    filter: 'H4sIAAAAAAAAA+2aW28TRxTHv4q1T63kSrMXr+28lUDphRZaKLcqD2mbXlSaSpRWQlUkSOrEMZAL5IqTkNIYp4BDQi51bAxfZmfXfupXqLxz5swZs7FcJaoilLf8f2fO2T2z451/xv7NCKa268VhPlo0ur74zfih77rRZfz8lRE3+nt/7DO6jGCjypduGXHj194rv/SFg/qNLoNnVhtDq01sdBnGQFzQ+vodPzsHFISM+YNPg5lJiIGQMZ6d9F4+ghgIjI0N8/HnMiYExsZX6n9mZEwIvF7pkfdyWV5PCMwbzvuzmCcE5mXnvMqozBMC82YWmjMFeULIWGPxrj9XgBgInJfVG/6QvB4IrHlzhw+Ny5pCYGxth1dKMiYExna3vOqfMiaEupe/+GQN7yUUqvcFf3ESew8F5g3VeHlQ5gmBeZkdrzoj84QY6GlGxaLpvdrXq5YNX1jntysdLhuvXOL5Gl8pNuaHIaYhfVzj0bxffiZvUgg5Ing5xvOycRD4YJ8W/S25kEBgbHNd5YGgzV3v671KmmvOdq3D5ixmOcDCPwm3FbcptxS3KDcVNylnijPCzTRyM015SvEU5UnFk5S7iruUJxRPUK76NWm/purXpP2aql+T9muqfk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LPoUkS4ujsQfI36+yhjaFrPJr5HzzdcSDHj1zeYXJ5ws+N7vLsk3puMMivHVk6WuhQ+ztac19mjxY6MOdHi0bYQBk4IBNIi75xjhDS9c8KxCKL/VfPqBXen4OEItqnSMYii3XiMbVi+3actNhh85/axLZ48rZejr7UQKBXbXPw2M6r8tpGvSjPlUBQ74grHwT2QBdyy/80jcW7fF3OJQiM0UcHohNv3HyX3p7BOQsF9pB5GuRzsgchVKz9wdyX33/7de919SDruUF/ttDpg5wr1HPyG00Q6sJDfG0bLxwKzCtn/Dn5kEFgXm6T51ZVWaXp9O5uqRFKq2uXvPINvHYocJKfPON35F4NAhdReYivyFcJCLzn6XlezpJ2UavsUlC8hdmhwDvK13gFl5kQ2M/IncbcpmxGiCMve+Rl9/ay/vJ4kF/jK0WeWaVe9vuv9+VjNRt74szJbtNOuUnHSTHHdphJvjalBnTv8ZY+3tbe3xHjbX28E+E9I7IcPSuh7QQR45P6eFczjhHjU/r4ZIQ/jMhK61mpVof3egr5j5e6sr3Ht0yvdF57J7TML57F7ZnQMrW6a9o7LdGSZmsbfkSC25LgaG4pIqHlGUqHs3dCy0M0XV4o+Euz/PYuz2hP0bUd12YWS7JEin7BH2GJaFrCtdO2lXQs13RTSStySda3W5eM46astJNMJBKuG368yFv/G+KueHY42KgegLtq+/VsG3fFbxZ45W+5fQmBeVMP/C15PRCdOKh2Tk9MMzq2UGB/m9P+c+xPiI6cHl1TIJTpaH4fj44jFHiflcd8bUnepxAducA2Ti/SddKHf+V//S7yaK8/pHv9ARxTN4+mQ9L8QzFbMlsxSzJLMVMyUzEmGUNmpoGZacVSkqUUS0qWVMyVzFUsIVmCTsOPP/Vf+07Ng7+Q7fy4Hn8ARnwM/liMeBX8YRnxI/gjNOI28Adr5Odq+OM28tM2/CEccR54cE3cBR5yE++AB+LEHODhOTk6x4P2pinoGegZ+Bd3sfXaeywAAA==',
    headers: {
        'User-Agent': 'PC_UA'
    },
    timeout: 10000,
    play_parse: true,


    lazy: $js.toString(() => {

        let id = input.split("|")[0];
        let k4 = input.split("|")[1];
        let url = `https://newcntv.qcloudcdn.com/asp/hls/850/0303000a/3/default/${id}/850.m3u8`;
        let kurl = `https://newcntv.qcloudcdn.com/asp/hls/4000/0303000a/3/default/${id}/4000.m3u8`;
        if (k4 === '7') {
            input = {
                parse: 0,
                url: kurl
            }
        } else
            input = {
                parse: 0,
                url: url,
                jx: 0

            }
    }),


    limit: 6,
    double: false,

    推荐: $js.toString(() => {
        var d = [];
        var list = JSON.parse(request(input)).response.docs;

        list.forEach(it => {
            // 一级标题
            let title1 = it.column_name;
            // 一级描述
            let desc1 = it.channel_name;
            // 一级图片URL
            let picUrl1 = it.column_logo;
            // 一级URL（id 地区 类型 标题 演员 年份 频道 简介 图片 更新至）
            let url1 = it.lastVIDE.videoSharedCode + '|' + '' + '|' + it.column_firstclass + '|' + it.column_name + '|' + '' + '|' + it.column_playdate + '|' + it.channel_name + '|' + it.column_brief + '|' + it.column_logo + '|' + '' + '|' + it.lastVIDE.videoTitle;

            d.push({
                desc: desc1,
                title: title1,
                pic_url: picUrl1,
                url: url1
            })
        })
        setResult(d);
    }),


    一级: $js.toString(() => {
        var d = [];
        if (MY_CATE === '栏目大全') {
            var list = JSON.parse(request(HOST + '/lanmu/columnSearch?&fl=&fc=&cid=&p=' + MY_PAGE + '&n=500&serviceId=tvcctv&t=json')).response.docs;
            list.forEach(it => {
                // 一级标题
                let title1 = it.column_name;
                // 一级描述
                let desc1 = it.channel_name;
                // 一级图片URL
                let picUrl1 = it.column_logo;
                // 一级URL（id 地区 类型 标题 演员 年份 频道 简介 图片 更新至）
                let url1 = it.lastVIDE.videoSharedCode + '|' + '' + '|' + it.column_firstclass + '|' + it.column_name + '|' + '' + '|' + it.column_playdate + '|' + it.channel_name + '|' + it.column_brief + '|' + it.column_logo + '|' + '' + '|' + it.lastVIDE.videoTitle;
                d.push({
                    desc: desc1,
                    title: title1,
                    pic_url: picUrl1,
                    url: url1
                })
            })
        } else if (MY_CATE === '4K专区') {
            var list = JSON.parse(request(HOST + '/NewVideo/getLastVideoList4K?serviceId=cctv4k&cid=&p=' + MY_PAGE + '&n=500&serviceId=tvcctv&t=json')).data.list;
            list.forEach(it => {
                // 一级标题
                let title1 = it.title;
                // 一级描述
                let desc1 = it.sc + ((typeof it.year === 'undefined' || it.year === '') ? '' : ('•' + it.year)) + ((typeof it.count === 'undefined' || it.count === '') ? '' : ('•共' + it.count + '集'));
                // 一级图片URL
                let picUrl1 = it.image;
                // 一级URL（id 地区 类型 标题 演员 年份 频道 简介 图片 集数）
                let url1 = it.id + '|' + it.area + '|' + it.sc + '|' + it.title + '|' + it.actors + '|' + it.year + '|' + it.channel + '|' + it.brief + '|' + it.image + '|' + it.count + '|' + '' + '|' + MY_CATE;
                d.push({
                    desc: desc1,
                    title: title1,
                    pic_url: picUrl1,
                    url: url1
                })
            })

        } else {
            var channelMap = {
                "特别节目": "CHAL1460955953877151",
                "纪录片": "CHAL1460955924871139",
                "电视剧": "CHAL1460955853485115",
                "动画片": "CHAL1460955899450127",
            };
            var list = JSON.parse(request(input + '&channelid=' + channelMap[MY_CATE] + '&fc=' + MY_CATE + '&p=' + MY_PAGE)).data.list;
            list.forEach(it => {
                // 一级标题
                let title1 = it.title;
                // 一级描述
                let desc1 = it.sc + ((typeof it.year === 'undefined' || it.year === '') ? '' : ('•' + it.year)) + ((typeof it.count === 'undefined' || it.count === '') ? '' : ('•共' + it.count + '集'));
                // 一级图片URL
                let picUrl1 = it.image;
                // 一级URL（id 地区 类型 标题 演员 年份 频道 简介 图片 集数）
                let url1 = it.id + '|' + it.area + '|' + it.sc + '|' + it.title + '|' + it.actors + '|' + it.year + '|' + it.channel + '|' + it.brief + '|' + it.image + '|' + it.count + '|' + '' + '|' + MY_CATE;
                d.push({
                    desc: desc1,
                    title: title1,
                    pic_url: picUrl1,
                    url: url1
                })
            })
        }
        setResult(d);
    }),

    二级: $js.toString(() => {
        let info = input.split("|");

        VOD = {
            vod_id: info[0],
            vod_name: info[3],
            vod_pic: info[8],
            type_name: info[2] === 'undefined' ? '' : info[2],
            vod_year: info[5] === 'undefined' ? '' : info[5],
            vod_area: info[1] === 'undefined' ? '' : info[1],
            vod_remarks: info[9] === '' ? ('更新至' + info[10]) : ('共' + info[9] + '集'),
            vod_director: info[6] === 'undefined' ? '' : info[6],
            vod_actor: info[4] === 'undefined' ? '' : info[4],
            //   vod_content: info[7]==='undefined'?'':info[7],

        };
        var modeMap = {
            "4K专区": "0",
            "特别节目": "0",
            "纪录片": "0",
            "电视剧": "0",
            "动画片": "1",

        };
        var ctid = info[0].replace('https://api.cntv.cn/lanmu/', '');
        var link = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?id=' + ctid + '&serviceId=tvcctv&p=1&n=100&mode=' + modeMap[info[11]] + '&pub=1';
        var html = JSON.parse(request(link));
        var playUrls;
        if (html.errcode === '1001') {
            var guid = info[0].replace('https://api.cntv.cn/lanmu/', '');
            var link1 = 'https://api.cntv.cn/video/videoinfoByGuid?guid=' + guid + '&serviceId=tvcctv';
            ctid = JSON.parse(request(link1)).ctid.replace('https://api.cntv.cn/lanmu/', '');
            var link2 = 'https://api.cntv.cn/NewVideo/getVideoListByColumn?id=' + ctid + '&d=&p=1&n=100&sort=desc&mode=0&serviceId=tvcctv&t=json';
            playUrls = JSON.parse(request(link2)).data.list;

        } else {
            playUrls = html.data.list;
            // 获取更多数据，暂不需要
            var flag = '';
            if (playUrls === '') {
                flag = 'true';
            }
            var page = 1;
            while (flag === '') {
                page = page + 1;
                var burl = 'https://api.cntv.cn/NewVideo/getVideoListByAlbumIdNew?id=' + ctid + '&serviceId=tvcctv&p=' + page + '&n=100&mode=' + modeMap[info[11]] + '&pub=1';
                var list = JSON.parse(request(burl)).data.list;
                if (list.length !== 0) {
                    list.forEach(it => {
                        playUrls.push(it);
                    })
                    continue;
                } else {
                    flag = 'true';
                    break;
                }
            }
        }

        let playFrom = [];
        let playList = [];
        playFrom.append('央视频');
        playUrls.forEach(it => {
            playList.append(playUrls.map(function(it) {
                return it.title + "$" + it.guid + "|" + it.type
            }).join("#"))
        });

        // 最后封装所有线路
        //    let  vod_content = playUrls;
        let vod_play_from = playFrom.join('$$$');
        let vod_play_url = playList.join('$$$');
        VOD['vod_play_from'] = vod_play_from;
        VOD['vod_play_url'] = vod_play_url;
    }),

    搜索: '',
}